<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/29/12
 * Time: 12:29 AM
 */
class Historial extends CT_Model
{
    function __construct()
    {
        parent::__construct();
        $this->table="CT_historiales";
    }

    function findFotos($columns,$tokens,$start, $limit){

        $start= empty($start)?0:$start;

        $this->db->select($columns);
        $this->db->from('CT_historiales_fotos');
        if(!empty($tokens))
            $this->db->where($tokens);
        $this->db->where('estatus = 1');
        $this->db->limit($limit,$start);
        $this->db->order_by('foto_k','desc');


        $query=$this->db->get();
        $data= $query->result();


        $this->db->select($columns);
        $this->db->from('CT_historiales_fotos');
        if(!empty($tokens))
            $this->db->where($tokens);
        $this->db->where('estatus = 1');
        $this->db->order_by('foto_k','desc');

        $query= (object) $this->db->get();
        $numRows= $query->num_rows();

        return array("data"=>$data,"total"=>$numRows);
    }

    function findPrincipal($columns,$tokens,$start, $limit){
        $start= empty($start)?0:$start;

        $this->db->select($columns,false);
        $this->db->from('CT_historiales h');
        $this->db->join('CT_historiales_fotos hf','h.historial_k = hf.historial_k');
        $this->db->group_by('h.historial_k');
        if(!empty($tokens))
            $this->db->where($tokens);
        $this->db->where('h.estatus = 1');
        $this->db->where('hf.estatus = 1');
        $this->db->limit($limit,$start);
        $this->db->order_by('h.fecha','desc');


        $query=$this->db->get();
        $data= $query->result();


        $this->db->select($columns,false);
        $this->db->from('CT_historiales h');
        $this->db->join('CT_historiales_fotos hf','h.historial_k = hf.historial_k');
        $this->db->group_by('h.historial_k');
        if(!empty($tokens))
            $this->db->where($tokens);
        $this->db->where('h.estatus = 1');
        $this->db->where('hf.estatus = 1');
        $this->db->order_by('h.fecha','desc');

        $query= (object) $this->db->get();
        $numRows= $query->num_rows();

        return array("data"=>$data,"total"=>$numRows);

    }
}
